SHELL=/bin/bash
ifeq ($(JAVA_HOME),)
$(error JAVA_HOME not set in environment)
endif

CC = D:/Software/mingw64/bin/g++

OS_DIR_WIN32_X86_64 := ../os/win32/x86_64
OS_DIR_LINUX_X86_64 := ../os/linux/x86_64

COMMON_CFLAGS :=  -Wall

UNAME = $(shell uname)
ifeq ($(UNAME),Linux)
LIBS = \
	$(OS_DIR_LINUX_X86_64)/native_bsp_tool.so
else
LIBS = \
	$(OS_DIR_WIN32_X86_64)/native_bsp_tool.dll
endif

all: $(LIBS)

clean:
	$(RM) $(LIBS)

rebuild: clean all

$(OS_DIR_WIN32_X86_64)/native_bsp_tool.dll: src/native_bsp_tool.cpp
	mkdir -p $(dir $@) && \
	$(CC) $(COMMON_CFLAGS) -o $@ -Iinclude -Isrc/include -I"$(JAVA_HOME)/include" -I"$(JAVA_HOME)/include/win32" \
		-DUNICODE \
		$^ \
		-Wl,--kill-at --shared -L$(OS_DIR_WIN32_X86_64) -lbsp_tool -static-libstdc++ -static-libgcc

$(OS_DIR_LINUX_X86_64)/libnative_bsp_tool.so: src/native_bsp_tool.cpp
	mkdir -p $(dir $@) && \
	$(CC) $(COMMON_CFLAGS) -m64 -o $@ -Wl,-soname,$(notdir $@) -Iinclude -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux -fpic \
		-D_REENTRANT -D_GNU_SOURCE \
		$^ \
		-shared -lc -lbsp_tool
